package project.active;

import java.util.ArrayList;

import project.model.PrTestProject;
import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import approve.action.R;

public class L_list_lsterr extends BaseAdapter implements OnItemClickListener {

	private Context context;
	ArrayList<PrTestProject> lsterr = new ArrayList<PrTestProject>();
	String id;
	
	public L_list_lsterr(Context context1,ArrayList<PrTestProject> lstem1,String dss){
		this.context=context1;
		this.lsterr=lstem1;
		this.id=dss;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return lsterr.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return lsterr.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final PrTestProject adpr = lsterr.get(position);
		String tnv="";
		if(convertView==null){
			LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView=inflater.inflate(R.layout.l_list_lsterr, null);
		}
		
		TextView tverrname=(TextView)convertView.findViewById(R.id.ad_l_tv_errname);
		TextView idtime=(TextView)convertView.findViewById(R.id.ad_l_tv_erridtime);
		
		//System.out.println("mau: "+adpr.getColorText());
		
		tnv=id+": "+adpr.getTitleview();
		Spannable WordtoSpan = new SpannableString(tnv);        
		WordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor(adpr.getColorText())), 0, tnv.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		tverrname.setText(WordtoSpan);
		
		tnv=" ( "+adpr.getDisplayDate()+" - "+adpr.getEmployeeName()+" )";
		WordtoSpan = new SpannableString(tnv);
		WordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor(adpr.getColorText())), 0, tnv.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		idtime.setText(WordtoSpan);
		
		
		//tverrname.setText(adpr.getTitle()+" ( "+adpr.getDisplayDate()+")");
		//idtime.setText(id+": "+adpr.getIdTest());
		
		return convertView;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		
	}

}
